<?php

namespace App\Models\Schedule;

use App\Models\BaseModel;
use App\Models\Traits\KfSoftDeletes;
use App\Models\Traits\KfUid;

class ScheduleRemindSwitchModel extends BaseModel
{
    use KfUid;
    use KfSoftDeletes;

    protected $table = "schedule_remind_switch";

    protected $fillable = [
        'userId',
        'type',
        'switch',
    ];

    const TYPE_SCHEDULE = 1;
    const TYPE_WORK     = 2;

    const TYPE_TEXT_MAPPING = [
        self::TYPE_SCHEDULE => '排班提醒',
        self::TYPE_WORK     => '上班提醒',
    ];

    const SWITCH_OFF = 0;
    const SWITCH_ON  = 1;

    const SWITCH_TEXT_MAPPING = [
        self::SWITCH_OFF => '关闭',
        self::SWITCH_ON  => '打开',
    ];

    public static function insertData(array $data)
    {
        return self::query()->create($data);
    }

    public static function getSwitchData($userId)
    {
        return self::query()
            ->where('userId', $userId)
            ->get()
            ->map(
                function ($switch) {
                    return [
                        'id'       => $switch['id'],
                        'type'     => $switch['type'],
                        'typeText' => self::TYPE_TEXT_MAPPING[$switch['type']] ?? "",
                        'switch'   => $switch['switch'],
                    ];
                }
            );
    }
}
